import 'package:distribution_mall_flutter/generated/json/base/json_convert_content.dart';
import 'package:distribution_mall_flutter/pages/goods/product_details/state/address_state.dart';
import 'package:distribution_mall_flutter/entity/address/address_entity.dart';


AddressState $AddressStateFromJson(Map<String, dynamic> json) {
  final AddressState addressState = AddressState();
  final List<AddressItem>? addressList = (json['addressList'] as List<dynamic>?)
      ?.map(
          (e) => jsonConvert.convert<AddressItem>(e) as AddressItem)
      .toList();
  if (addressList != null) {
    addressState.addressList = addressList;
  }
  final SelectAddressItem? userSelectAddress = jsonConvert.convert<
      SelectAddressItem>(json['userSelectAddress']);
  if (userSelectAddress != null) {
    addressState.userSelectAddress = userSelectAddress;
  }
  final List<
      AddressDeliveryTimeEntity>? addrDeTime = (json['addrDeTime'] as List<
      dynamic>?)?.map(
          (e) =>
      jsonConvert.convert<AddressDeliveryTimeEntity>(
          e) as AddressDeliveryTimeEntity).toList();
  if (addrDeTime != null) {
    addressState.addrDeTime = addrDeTime;
  }
  return addressState;
}

Map<String, dynamic> $AddressStateToJson(AddressState entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['addressList'] = entity.addressList.map((v) => v.toJson()).toList();
  data['userSelectAddress'] = entity.userSelectAddress?.toJson();
  data['addrDeTime'] = entity.addrDeTime.map((v) => v.toJson()).toList();
  return data;
}

extension AddressStateExtension on AddressState {
  AddressState copyWith({
    List<AddressItem>? addressList,
    SelectAddressItem? userSelectAddress,
    List<AddressDeliveryTimeEntity>? addrDeTime,
  }) {
    return AddressState()
      ..addressList = addressList ?? this.addressList
      ..userSelectAddress = userSelectAddress ?? this.userSelectAddress
      ..addrDeTime = addrDeTime ?? this.addrDeTime;
  }
}

SelectAddressItem $SelectAddressItemFromJson(Map<String, dynamic> json) {
  final SelectAddressItem selectAddressItem = SelectAddressItem();
  final AddressItem? item = jsonConvert.convert<AddressItem>(json['item']);
  if (item != null) {
    selectAddressItem.item = item;
  }
  final String? recipientName = jsonConvert.convert<String>(
      json['recipientName']);
  if (recipientName != null) {
    selectAddressItem.recipientName = recipientName;
  }
  final String? phone = jsonConvert.convert<String>(json['phone']);
  if (phone != null) {
    selectAddressItem.phone = phone;
  }
  final String? address = jsonConvert.convert<String>(json['address']);
  if (address != null) {
    selectAddressItem.address = address;
  }
  final String? virtualPostcode = jsonConvert.convert<String>(
      json['virtualPostcode']);
  if (virtualPostcode != null) {
    selectAddressItem.virtualPostcode = virtualPostcode;
  }
  return selectAddressItem;
}

Map<String, dynamic> $SelectAddressItemToJson(SelectAddressItem entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['item'] = entity.item.toJson();
  data['recipientName'] = entity.recipientName;
  data['phone'] = entity.phone;
  data['address'] = entity.address;
  data['virtualPostcode'] = entity.virtualPostcode;
  return data;
}

extension SelectAddressItemExtension on SelectAddressItem {
  SelectAddressItem copyWith({
    AddressItem? item,
    String? recipientName,
    String? phone,
    String? address,
    String? virtualPostcode,
  }) {
    return SelectAddressItem()
      ..item = item ?? this.item
      ..recipientName = recipientName ?? this.recipientName
      ..phone = phone ?? this.phone
      ..address = address ?? this.address
      ..virtualPostcode = virtualPostcode ?? this.virtualPostcode;
  }
}